DojoManager.Athletes = Ext.extend(Ext.app.Module, {

    getId : function() {
        return 'athletes';
    },

    init : function(){
        this.launcher = {
            text: 'Atleti',
            iconCls: 'tabs',
            handler: this.createWindow,
            scope: this
        }
    },

    createWindow : function(){

        var desktop = this.app.getDesktop();
        var win = desktop.getWindow(this.getId());
        if (!win) {
            win = desktop.createWindow({
                id: this.getId(),
                title: 'Atleti',
                width: 730,
                height: 400,
                iconCls: 'tabs',
                shim: false,
                layout: 'fit',
                tbar:[{
                        id: 'add-btn',
                        text: 'Aggiungi',
                        tooltip: 'Aggiungi nuovo atleta',
                        iconCls: 'add'
                    }, {
                        id: 'remove-btn',
                        text: 'Rimuovi',
                        tooltip: 'Rimuovi l\'atleta selezionato',
                        iconCls: 'remove'
                    }
                ],
                items: [
                    new Ext.grid.GridPanel({
                        id: 'athletes-grid',
                        region: 'center',
/*
                        ds: Ext.data.JsonStore({
                            autoLoad: true,
                            url: 'pages/get-athletes.php',
                            root: 'items',
                            fields: ['surname', 'name', 'birthday', 'dojo', 'belt']
                        }),
                        cm: new Ext.grid.ColumnModel([
                            {id: 'surname', header: 'Cognome', width: 200, sortable: true, dataIndex: 'surname'},
                            {id: 'name', header: 'Nome', width: 200, sortable: true, dataIndex: 'name'},
                            {id: 'birthday', header: 'Data di nascita', width: 120, sortable: true, dataIndex: 'birthday'},
                            {id: 'dojo', header: 'Palestra', width: 120, sortable: true, dataIndex: 'dojo'},
                            {id: 'belt', header: 'Cintura', width: 120, sortable: true, dataIndex: 'belt'}                                
                        ]),
*/
                        ds: new Ext.data.Store({
                                autoLoad: true,
                                proxy: new Ext.data.HttpProxy({
                                    url: 'dojo/pages/get-athletes.php'
                                }),
                                reader: new Ext.data.JsonReader({
                                    totalProperty: 'results',
                                    id: 'id',
                                    root: 'items'
                                }, ['surname', 'name', 'birthday', 'dojo', 'belt', 'weight'])
                        }),
                        cm: new Ext.grid.ColumnModel([
                            {id: 'surname', header: 'Cognome', width: 200, sortable: true, dataIndex: 'surname'},
                            {id: 'name', header: 'Nome', width: 200, sortable: true, dataIndex: 'name'},
                            {id: 'birthday', header: 'Data di nascita', width: 120, sortable: true, dataIndex: 'birthday'},
                            {id: 'dojo', header: 'Palestra', width: 120, sortable: true, dataIndex: 'dojo'},
                            {id: 'belt', header: 'Cintura', width: 120, sortable: true, dataIndex: 'belt'},
                            {id: 'weight', header: 'Peso', width: 120, sortable: true, dataIndex: 'weight'}
                        ])
                    })
                ],
                buttons: [
                 {
                    text: 'Close',
                    handler: function() {
                        win.close();
                    }
                 }]
            });
        }

        win.show();
    }
});
